package org.zjt.spi;

import lombok.extern.slf4j.Slf4j;
import org.zjt.i18n.LocalTest;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.spi.ResourceBundleControlProvider;

/**
 * @author juntao.zhang
 * @version V1.0
 * @Description: TODO
 * @Package org.zjt.spi
 * @date 2018/5/30 23:51
 */
@Slf4j
public class MyResourceBundleControlProvider implements ResourceBundleControlProvider {

    @Override
    public ResourceBundle.Control getControl(String baseName) {
        log.info(baseName);
        LocalTest.EncodingResourceBundleControl GBKEncodingResourceBundleControl = new LocalTest.EncodingResourceBundleControl("GBK");
        return GBKEncodingResourceBundleControl;
    }

    public static void main(String[] args) throws IOException {

        InputStream inputStream = Files.newInputStream(Paths.get("F:\\Idea workspace\\java-basic\\src\\resource\\app.properties"));
        PropertyResourceBundle propertyResourceBundle = new PropertyResourceBundle(inputStream);

        Object name = propertyResourceBundle.handleGetObject("name");

        System.err.println(name);
    }
}
